package com.xjgc.eip.twice.zxjeip2cxtld.controller;


import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.jeecg.common.api.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xjgc.common.constant.Consants;
import com.xjgc.common.entity.ReturnResult;
import com.xjgc.eip.twice.zxjeip2cccjc.service.ZxjEip2cCcjcService;
import com.xjgc.eip.twice.zxjeip2cxtld.entity.ZxjEip2cXtld;
import com.xjgc.eip.twice.zxjeip2cxtld.service.ZxjEip2cXtldService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhanghongbin
 * @since 2019-11-23
 */
@Slf4j
@Api(tags = "系统联调接口")
@RestController
@RequestMapping("/apis/zxjEip2cXtld")
public class ZxjEip2cXtldController {
@Autowired
    ZxjEip2cXtldService zxjEip2cXtldService;
    @Autowired
    ZxjEip2cCcjcService zxjEip2cCcjcService;
    /**
     * 系统联调接口
     */
    @ApiOperation("系统联调接口")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "amount", value = "查询条数",
                    required = true,dataType = "int")
    })
    @GetMapping(value = "/getData")
    @ResponseBody
    public ReturnResult getData(Integer amount,@RequestHeader(name = "supplierCode",required = false)String supplierCode) {
        ReturnResult returnResult = zxjEip2cXtldService.getData(amount,supplierCode);
        return returnResult;
    }
    @RequestMapping(value="/list")
    public Result<IPage<ZxjEip2cXtld>> findlist(ZxjEip2cXtld xtld,
                                                   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                                   HttpServletRequest req) {

        Result<IPage<ZxjEip2cXtld>> result = zxjEip2cXtldService.findByCcList(xtld,pageNo,pageSize,req);
        return  result;
    }
    @RequestMapping(value="/reviewListPage")
    public Result<?> reviewListPage(ZxjEip2cXtld xtld,
                                                @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                                HttpServletRequest req) {
        QueryWrapper<ZxjEip2cXtld> queryWrapper = new QueryWrapper<ZxjEip2cXtld>();
        xtld.setReviewStatus(Consants.REVIEW_STATUS1);//装置检测审批通过
        queryWrapper.setEntity(xtld);
        Page<ZxjEip2cXtld> page = new Page<ZxjEip2cXtld>(pageNo, pageSize);
        IPage<ZxjEip2cXtld> pageList = zxjEip2cXtldService.page(page, queryWrapper);
        return Result.ok(pageList);
    }
    /**
     *  批量审批
     * @param
     * @return
     */
    @RequestMapping(value = "/updateBatch")
    public Result<?> updateBatch(@RequestBody List<ZxjEip2cXtld> data) {
        Boolean flag = zxjEip2cXtldService.updateBatch(data);
        if (flag){
            return Result.ok("审批成功");
        }else {
            return  Result.error("审批失败");
        }
    }
}

